/************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
  * @file     tp_rtp.h
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-01
  * @brief     
 *************************************************************************/

#ifndef _TP_RTP_H
#define _TP_RTP_H

#include "eport_drv.h"
#include "data.h"

/*-------------------------------------------RTP GPIO ------------------------------*/
//   XM = X-  
//   XP = X+  
//   YM = Y-  
//   YP = Y+
#if (LT_TOUCH_FLAG == 1)
#define RTP_XM_OUT		 EPORT_ConfigGpio(EPORT_PIN33, GPIO_OUTPUT)  // X- configure as GPIO output
#define RTP_XM_IN	 	 EPORT_ConfigGpio(EPORT_PIN33, GPIO_INPUT)   // X- configure as GPIO input
#define RTP_XM_UP		 EPORT_PullupConfig(EPORT_PIN33, ENABLE)     // X- configured as pull-up
#define RTP_XM_DOWN		 EPORT_PullupConfig(EPORT_PIN33, DISABLE)    // X- configure as pull-down
#define RTP_XM_LEVEL(x)	 EPORT_WriteGpioData(EPORT_PIN33, x)         // X- output high or low level

#define RTP_XP_OUT		 I2C_ConfigGpio(I2C1, I2C_SDA, GPIO_OUTPUT)
#define RTP_XP_IN		 I2C_ConfigGpio(I2C1, I2C_SDA, GPIO_INPUT)
#define RTP_XP_UP		 I2C->PCR |= (1 << 1)
#define RTP_XP_DOWN		 I2C->PCR &= ~(1 << 1)
#define RTP_XP_LEVEL(x)  I2C_WriteGpioData(I2C1, I2C_SDA, x)

#define RTP_YM_OUT 		EPORT_ConfigGpio(EPORT_PIN34, GPIO_OUTPUT)
#define RTP_YM_IN 		EPORT_ConfigGpio(EPORT_PIN34, GPIO_INPUT)
#define RTP_YM_UP 		EPORT_PullupConfig(EPORT_PIN34, ENABLE)
#define RTP_YM_DOWN		EPORT_PullupConfig(EPORT_PIN34, DISABLE)
#define RTP_YM_LEVEL(x) EPORT_WriteGpioData(EPORT_PIN34, x)

#define RTP_YP_OUT 		I2C_ConfigGpio(I2C1, I2C_SCL, GPIO_OUTPUT)
#define RTP_YP_IN 		I2C_ConfigGpio(I2C1, I2C_SCL, GPIO_INPUT)
#define RTP_YP_UP 		I2C->PCR |= (1 << 0)
#define RTP_YP_DOWN 	I2C->PCR &= ~(1 << 0)
#define RTP_YP_LEVEL(x) I2C_WriteGpioData(I2C1, I2C_SCL, x)
#endif

uint8_t LT_TpInit(void);
uint8_t LT_TpScan(void);
uint8_t LT_TpAdjust(void);
void LT_TpSaveAdjdata(void);
uint8_t LT_TpGetAdjdata(void);
uint8_t TP_Read_XY2(uint16_t *x, uint16_t *y);

#endif /* _TP_RTP_H */
